{{ define "email_template.html"  }}

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style>
    .alert-table {
      width: 100%;
      border-collapse: collapse;
      margin: 20px 0;
    }
    .alert-table th {
      background: #f8f9fa;
      padding: 12px;
      text-align: left;
    }
    .alert-table td {
      padding: 10px;
      border: 1px solid #e9ecef;
    }
    .critical { background: #ffe3e3; }
    .warning { background: #fff3bf; }
    .resolved { background: #d3f9d8; }
  </style>
</head>
<body>
   <h3>
	{{- if eq .Status "firing" -}}
	❌  [FIRING] {{ .CommonLabels.alertname }} ({{ len .Alerts }} alerts)
	{{- else -}}
	✅  [RESOLVED] {{ .CommonLabels.alertname }} ({{ len .Alerts }} alerts)
	{{- end }}
   </h3>

  <table class="alert-table">
    <tr>
      <th>状态</th>
      <th>实例</th>
      <th>详情</th>
      <th>触发时间</th>
      <th>恢复时间</th>
    </tr>
    {{ range .Alerts }}
    <tr class="{{ if and (eq .Status "firing") (eq .Labels.severity  "critical") }}critical 
           {{ else if and (eq .Status "firing") (eq .Labels.severity  "warning") }}warning 
           {{ else }}resolved{{ end }}">
      <td>{{ .Status | title }}</td>
      <td>{{ .Labels.instance  }}</td>
      <td>{{ .Annotations.description  }}</td>
      <td>{{ (.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}</td>
      <td>
         {{ if .EndsAt.IsZero }}持续中{{ else }}{{ (.EndsAt.Add 28800e9).UTC.Format "2006-01-02 15:04:05" }}{{ end }}
      </td>
    </tr>
    {{ end }}
  </table>
</body>
</html>

{{ end }}
